package chapter18;

import java.util.Arrays;
import java.util.Collection;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/3/24 18:30
 */
public class PPrint {
    public static String pFormat(Collection<?> c) {
        if (c == null || c.size() == 0) {
            return "[]";
        }

        StringBuilder builder = new StringBuilder("[");
        for (Object o : c) {
            if (c.size() != 1) {
                builder.append("\n ");
            }
            builder.append(o);
        }

        if (c.size() != 1) {
            builder.append("\n");
        }

        builder.append("]");
        return builder.toString();
    }

    public static void pprint(Collection<?> c) {
        System.out.println(pFormat(c));
    }

    public static void pprint(Object[] objects) {
        System.out.println(pFormat(Arrays.asList(objects)));
    }
}
